﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>
<script runat="server">

    private string c_dt;

    protected void Button1_Click(object sender, EventArgs e)
    {
        User curLoginUser = (User)Session["user"];
        if (ViewState["c_dt"] != null)
        {
            c_dt = (string)ViewState["c_dt"];
        }
        
        string calendarTitle = Request.Form.Get(this.TxtTitle.ClientID);

        //检测事务标题不能为空，为空则返回 
        if (string.IsNullOrEmpty(calendarTitle.Trim()))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务标题不能为空！');", true);
            return;
        }
        
        string startTime = TxtStart.Text;
        //检测开始时间是否为空，为空则返回 
        if (string.IsNullOrEmpty(startTime.Trim()))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('开始时间不能为空！');", true);
            return;
        }

        string endTime = TxtEnd.Text;
        //检测结束时间是否为空，为空则返回
        if (string.IsNullOrEmpty(endTime.Trim()))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('结束时间不能为空！');", true);
            return;
        }

        DateTime curDt = DateTime.Parse(c_dt);

        //检测时间间隔是否为空，为空则返回
        if (string.IsNullOrEmpty(IntervalMinute.Text.Trim()))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('时间间隔不能为空！');", true);
            return;
        }
        int intervalMinute = int.Parse(IntervalMinute.Text);
        
        string calendarContent = Request.Form.Get(this.TxtContent.ClientID);
        //检测事务内容是否为空，为空则返回
        if (string.IsNullOrEmpty(calendarContent.Trim()))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务内容不能为空！');", true);
            return;
        }
        
        string type = Request.Form.GetValues(this.selectCalType.ClientID)[0];
        UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
        int[] rev = ucatbService.saveUserCalendarArrangeInfo(calendarTitle, calendarContent, startTime, endTime, intervalMinute, curDt,
            type, curLoginUser.LoginName);
        if (rev[0] == 1)
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务添加成功！');", true);
            CalendarArrangeInfos cainfos = CalendarArrangeInfos.instance();
            List<UserCalendarArrangetb> list = (List<UserCalendarArrangetb>)cainfos.Cainfos[curLoginUser.LoginName];
            if (list != null)
            {
                if (curDt == DateTime.Parse(DateTime.Now.ToShortDateString()))
                {
                    list.Add(ucatbService.findByCaId(rev[1]));
                }
            }
            //返回到今日日程
            c_dt = Request.QueryString["c_dt"];
            this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务添加失败！');", true);
        }

        ViewState["c_dt"] = c_dt;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["c_dt"] != null)
            {
                c_dt = Request.QueryString["c_dt"];
                this.LblCurDate.Text = "(" + c_dt + ")";
                ViewState["c_dt"] = c_dt;
            }
        }

        if (Request.QueryString["c_dt"] != null)
        {
            c_dt = Request.QueryString["c_dt"];
            this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
        }
        else
        {
            c_dt = DateTime.Now.ToShortDateString().Replace("-", "/");
            this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ViewState["c_dt"] != null)
        {
            c_dt = (string)ViewState["c_dt"];
        }
        ViewState["c_dt"] = c_dt;
        Response.Redirect("CalendarArrangeShow.aspx?c_dt=" + c_dt);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />
    <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>
    <script type="text/javascript" src="../Scripts/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>
    <script type="text/javascript">
        function validateForm() {
            var title = $("#TxtTitle");
            var startTime = $("#TxtStart");
            var endTime = $("#TxtEnd");
            var interval = $("#IntervalMinute");
            var content = $("#TxtContent");

            var flag = true;

            if (title.val() == '') {
                alert("标题不能为空");
                flag = false;
            } else if (startTime.val() == '') {
                alert("开始时间不能为空");
                flag = false;
            } else if (endTime.val() == '') {
                alert("结束时间不能为空");
                flag = false;
            } else if (interval.val() == '') {
                alert("时间间隔不能为空");
                flag = false;
            } else if (content.val() == '') {
                alert("事务内容不能为空");
                flag = false;
            }
            return flag;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="sub_right_top">
        <!--滑动门-->
        <div class="hdm_header">
            <div class="tb1_off" id="tab1">
                <h2 class="h2_icon">
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/CalendarArrange/ArrangeIndex.aspx">日程安排</asp:HyperLink>
                </h2>
            </div>
            <div class="tb1_off" id="tab2">
                <h2 class="h2_icon">
                    <asp:HyperLink ID="HyperLink2" runat="server">今日日程</asp:HyperLink>
                </h2>
            </div>
            <div class="tb1_off" id="tab3">
                <h2 class="h2_icon">
                    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/CalendarArrange/CalendarArrangeDemand.aspx">日程查询</asp:HyperLink>
                </h2>
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="hdm_footer">
            <div id="tb1_2_content" class="cont01_word" style="display: block;">
                <div class="fabu_gg_title">
                    &nbsp;新建事务<asp:Label ID="LblCurDate" runat="server" Width="223px"></asp:Label></div>
                <table width="96%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0"
                    style="border-collapse: collapse;">
                    <tr bgcolor="#e4f1fd">
                        <td colspan="2" align="center">
                            <strong>新建事务信息</strong>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            事务标题：
                        </td>
                        <td>
                            <asp:TextBox ID="TxtTitle" runat="server" Width="377px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            开始时间：
                        </td>
                        <td>
                            <asp:TextBox ID="TxtStart" runat="server" CssClass="Wdate" onClick="WdatePicker({dateFmt:'HH:mm'})"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            结束时间：
                        </td>
                        <td>
                            <asp:TextBox ID="TxtEnd" runat="server" CssClass="Wdate" onClick="WdatePicker({dateFmt:'HH:mm'})"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            提醒间隔：
                        </td>
                        <td>
                            <asp:TextBox ID="IntervalMinute" runat="server" CssClass="Wdate" onClick="WdatePicker({dateFmt:'mm'})"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            事务类型：
                        </td>
                        <td>
                            <select id="selectCalType" runat="server" class="BigSelect" name="selectCalType"
                                style="width: 140px;">
                                <option value="1">工作事务</option>
                                <option value="2">个人事务</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="100" valign="top">
                            事务内容：
                        </td>
                        <td>
                            <asp:TextBox ID="TxtContent" runat="server" Height="140px" TextMode="MultiLine" Width="100%"
                                Font-Size="12px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td width="100">
                            &nbsp;
                        </td>
                        <td>
                            <div class="disk_queding_top">
                                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" OnClientClick="return validateForm();" />
                            </div>
                            <div class="disk_back_top">
                                <asp:Button ID="Button4" runat="server" Height="24px" Text="返回" Width="58px" OnClick="Button2_Click" />
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    </form>
</body>
</html>
